/**
 * Created by ZHOUSH on 12/24/2015.
 */
var server_err = function (res, params) {
    return function (err) {
        res.status(500).json({
            error: err.toString(),
            stack: err.stack,
            params: params
        });
        console.log(err.stack)
    }
};
var contains_array = function (arr, cb) {
    var found = arr.filter(function (item) {
        return cb(item);
    });
    if (found) return found[0];
    return undefined;
};
var distinct_array = function (arr, keys, filter) {
    return arr.reduce(function (pre, curr) {
        if (!contains_array(pre, function (item) {
                var eql = true;
                for (var prop in keys) {
                    if (keys.hasOwnProperty(prop)) {
                        if (!filter) {
                            eql = eql && (item[prop] == curr[prop]);
                        } else if (filter(prop, item[prop], curr[prop])) {
                            eql = eql && (item[prop] == curr[prop]);
                        }
                    }
                }
                return eql;
            })) {
            pre.push(curr);
        }
        return pre;
    }, []);
};
exports.server_err = server_err;
exports.distinct_array = distinct_array;